home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 428_02 / examples / runmenu.c < prev    next >
C/C++ Source or Header  |  1994-03-13  |  2KB  |  110 lines

  1. /*
  2. ** RUNMENU.C: Demonstrates use of the PICTOR menu system.
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <pictor.h>
  7.  
  8. /* set mainloop = FALSE to terminate main loop */
  9. int mainloop = TRUE;
  10.  
  11. VIDEOSTRUCT vstruct;
  12. COLORSTRUCT menucolors = {
  13.    foreback(BLACK,CYAN),
  14.    foreback(BOLD+WHITE,CYAN),
  15.    foreback(BOLD+CYAN,BLUE),
  16.    foreback(BOLD+WHITE,BLUE)
  17. };
  18.  
  19. /* give function references for menu tables */
  20. void sample(void);
  21. void terminate(void);
  22.  
  23. SUBMENU filemenu[] = {
  24.    { "~New                F2",
  25.       "Create a new file",NULL,sample },
  26.    { "~Open...",
  27.       "Open an existing file",NULL,sample },
  28.    { "~Save",
  29.       "Save the current file",NULL,sample },
  30.    { "Save ~As",
  31.       "Save the current file with a different name",
  32.       NULL,sample },
  33.    SUBMENU_DIVIDER,
  34.    { "E~xit","Exit to DOS",NULL,terminate },
  35.    END_SUBMENU
  36. };
  37.  
  38. SUBMENU editmenu[] = {
  39.    { "~Cut            Shift-Del",
  40.       "Move text to clipboard",NULL,sample },
  41.    { "C~opy",
  42.       "Copy text to clipboard",NULL,sample },
  43.    { "~Paste",
  44.       "Paste text from clipboard",NULL,sample },
  45.    END_SUBMENU
  46. };
  47.  
  48. MAINMENU mainmenu[] = {
  49.    { "~File","File operations menu",NULL,filemenu },
  50.    { "~Edit","Edit operations menu",NULL,editmenu },
  51.    END_MAINMENU
  52. };
  53.  
  54. void sample(void)
  55. {
  56.    beep();
  57. }
  58.  
  59. void terminate(void)
  60. {
  61.    mainloop = FALSE;
  62. }
  63.  
  64. void main()
  65. {
  66.    int i;
  67.  
  68.    /* initialize library */
  69.    initvideo();
  70.    getvconfig(&vstruct);
  71.  
  72.    /* hide text cursor */
  73.    showcurs(FALSE);
  74.  
  75.    /* Default shadow color is white on black. */
  76.    /* Since our desktop is white on black, we need to */
  77.    /* make shadows darker in order for them to show up */
  78.    _PL_shadowcolor = foreback(BOLD+BLACK,BLACK);
  79.  
  80.    /* create desktop */
  81.    for(i = 2;i < vstruct.rows;i++) {
  82.       setvpos(i,1);
  83.       vrepc('\xB1',vstruct.columns);
  84.    }
  85.    showmenu(mainmenu,&menucolors,FALSE);
  86.    initstatus(vstruct.rows,menucolors.normal);
  87.    statusbar("<Alt>=Menus  <F10>=Exit to DOS");
  88.  
  89.    while(mainloop) {
  90.       switch(runmenu(mainmenu,&menucolors,&menucolors)) {
  91.          case 0:     /* keystroke processed by runmenu */
  92.             break;
  93.          case F2_KEY:
  94.             sample();
  95.             break;
  96.          case F10_KEY:
  97.             mainloop = FALSE;
  98.             break;
  99.          default:
  100.             beep();
  101.             break;
  102.       }
  103.    }
  104.  
  105.    /* restore screen */
  106.    vcolor(foreback(WHITE,BLACK));
  107.    showcurs(TRUE);
  108.    cls();
  109. }
  110.